// region
class region{

	static initRegion(regSelectObjId) {
		debugger;
		$.ajax({
			type : 'get',
			url : '/pSuppliers/getRegion',
			async : false,
			success : function(data) {
				region.showSelect(regSelectObjId,data,1,null);

			}
		});
	}

	static initRegionWithRegId(regSelectObjId,regionCode) {
		regionCode= regionCode.toString();
		debugger;
		$.ajax({
			type : 'get',
			url : '/pSuppliers/getRegion',
			async : false,
			success : function(data) {
				if(regionCode){
					region.showSelect(regSelectObjId,data,1,regionCode.substr(0,2));
					
					$.ajax({
						type : 'get',
						url : '/pSuppliers/getRegion/'+regionCode.substr(0,2),
						async : false,
						success : function(data) {

							region.showSelect('region_select2',data,1,regionCode.substr(0,4));
							
							$.ajax({
								type : 'get',
								url : '/pSuppliers/getRegion/'+regionCode.substr(0,4),
								async : false,
								success : function(data) {

									region.showSelect('region_select3',data,1,regionCode);								

								}
							});
						}
					});
					
				}
			}
		});		
		
	}

	static queryRegion(regId,regionSelectObj) {
		debugger;
		$.ajax({
			type : 'get',
			url : '/pSuppliers/getRegion/'+regId,
			async : false,
			success : function(data) {
				region.showSelect(regionSelectObj,data,1,null);
			}
		});
	}

	static  showSelect(id, data, all , checked) {
		var select = $("#" + id);
		select.empty();

		if (all != undefined || all) {
			select.append("<option value=''>请选择</option>");
		}

		$.each(data, function(k, v) {
			let key = v.key;
			let value = v.value;
			let checkedHtml = "";
			if(checked!=null && key == checked){
				checkedHtml = " selected = 'selected' ";
			}
			select.append("<option value ='" + key + "' "+ checkedHtml +" >" + value + "</option>");
		});

		return data;
	}


}